#include "../../../common/mysql_chat_session_member.hpp"
#include "../../../odb/chat_session_member.hxx"
#include "chat_session_member-odb.hxx"
#include "../../../common/uuid.hpp"

#include <gflags/gflags.h>

DEFINE_bool(log_mode, false, "程序的运行模式: true-发布模式 false-调试模式");
DEFINE_string(log_file, "", "发布模式下，制定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，制定日志的输出等级");

void appendMember(bite_im::ChatSessionMemberTable &table)
{
    bite_im::ChatSessionMember member1;
    member1.session_id("会话-3");
    member1.user_id("3b70-49c7-dfe4-0004");
    table.append(member1);

    bite_im::ChatSessionMember member2;
    member2.session_id("会话-3");
    member2.user_id("5d71-92bf-2176-0003");
    table.append(member2);

    // bite_im::ChatSessionMember member3;
    // member3.session_id("会话-4");
    // member3.user_id("ad3a-7782-650d-0000");
    // table.append(member3);
    // bite_im::ChatSessionMember member4;
    // member4.session_id("会话-4");
    // member4.user_id("1f5d-e72e-e845-0001");
    // table.append(member4);
    // bite_im::ChatSessionMember member5;
    // member5.session_id("会话-4");
    // member5.user_id("3b70-49c7-dfe4-0004");
    // table.append(member5);
}

void appendMemberList(bite_im::ChatSessionMemberTable &table)
{
    std::vector<bite_im::ChatSessionMember> member_list;
    bite_im::ChatSessionMember member1;
    member1.session_id("会话2");
    member1.user_id("2022044026");

    bite_im::ChatSessionMember member2;
    member2.session_id("会话2");
    member2.user_id("2024044026");

    bite_im::ChatSessionMember member3;
    member3.session_id("会话3");
    member3.user_id("785d-5804-911f-0001");

    bite_im::ChatSessionMember member4;
    member4.session_id("会话3");
    member4.user_id("6dca-21e9-d37e-0001");

    member_list.push_back(member1);
    member_list.push_back(member2);
    member_list.push_back(member3);
    member_list.push_back(member4);
    table.append(member_list);
}

void removeMember(bite_im::ChatSessionMemberTable &table)
{
    bite_im::ChatSessionMember member1;
    member1.session_id("会话1");
    member1.user_id("fda3-38b9-d95e-0001");
    table.remove(member1);
}

void removeSession(bite_im::ChatSessionMemberTable &table)
{
    // table.remove("会话1");
    // table.remove("会话2");
    table.remove("会话-3");
    table.remove("会话-4");
}

void getMembers(bite_im::ChatSessionMemberTable &table)
{
    std::vector<std::string> members = table.members("会话1");
    for (auto str : members)
    {
        std::cout << str << std::endl;
    }
}

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    bite_im::initLogger(FLAGS_log_mode, FLAGS_log_file, FLAGS_log_level);

    auto db = bite_im::ODBFactory::create("root", "Czh432248", "ChatRoom",
                                          "127.0.0.1", 0, "utf8", 3);
    bite_im::ChatSessionMemberTable table(db);

    // appendMember(table);
    // std::this_thread::sleep_for(std::chrono::seconds(10));
    // removeSession(table);
    // removeSession(table);
    // appendMember(table);
    // appendMemberList(table);

    // removeMember(table);
    // removeSession(table);
    // getMembers(table);
    return 0;
}